﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScriptCoreLib;
using ScriptCoreLib.Shared.Avalon.Extensions;
using System.Windows.Controls;
using System.Windows.Media;

namespace AvalonTycoonMansion.Shared
{
	[Script]
	public class TycoonStatusbar : ISupportsContainer
	{
		public Canvas Container { get; set; }

		readonly TycoonButton BankAccountButton;
		readonly TycoonButton MessengerButton;
		readonly TycoonButton CalendarButton;

		int InternalBankAccount;
		public int BankAccount
		{
			get
			{
				return InternalBankAccount;
			}
			set
			{
				InternalBankAccount = value;

				if (value < 0)
					BankAccountButton.Foreground = Brushes.Red;
				else
					BankAccountButton.Foreground = Brushes.White;

				BankAccountButton.Text = value.ToDollarString();
			}
		}



		public string Messenger
		{
			get
			{
				return MessengerButton.Text;
			}
			set
			{
				MessengerButton.Text = value;
			}
		}

		int InternalCalendar;

		public int Calendar
		{
			get
			{
				return InternalCalendar;
			}
			set
			{
				InternalCalendar = value;

				var w = new StringBuilder();

				var m = value % 12;
				var y = (value - m) / 12;

				w.Append(y);
				w.Append(" yrs, ");
				w.Append(m);
				w.Append(" mnths");

				CalendarButton.Text = w.ToString();
			}
		}

		public readonly int Width;
		public readonly int Height;

		public TycoonStatusbar()
		{
			this.Width = 480;
			this.Height = 12;

			Container = new Canvas { Width = Width, Height = Height };

			BankAccountButton = new TycoonButton(140, 12)
			{
				Text = "$999,123"
			}.AttachContainerTo(this).MoveContainerTo(140 + 200, 0);

			MessengerButton = new TycoonButton(200, 12)
			{
				Text = "-- Avalon Tycoon Mansion --",
				Foreground = 0xffC8C8C8.ToSolidColorBrush()
			}.AttachContainerTo(this).MoveContainerTo(140, 0);

			CalendarButton = new TycoonButton(140, 12)
			{
				Text = "125 yrs, 3 mnths"
			}.AttachContainerTo(this).MoveContainerTo(0, 0);
		}
	}
}
